package com.itheima.controller;

import domain.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;
import java.util.List;

@Controller
public class UserController {

    @RequestMapping("req1")
    public String req1 (String name, String age){
        System.out.println("UserController save is running......"+name+age);
        return "success.jsp";
    }
    @RequestMapping("req2")
    public String req2 (@RequestParam(name="userName",required = true,
    defaultValue = "itheima")String name, String age){
        System.out.println("UserController save is running......"+name+age);
        return "success.jsp";
    }
    @RequestMapping("req3")
    public String req3(User user){
        System.out.println("UserController save is running......"+user);
        return "success.jsp";
    }
    @RequestMapping("req4")
    public String req4(User user,String age){
        System.out.println("UserController save is running......"+user+","+age);
        return "success.jsp";
    }
    @RequestMapping("req5")
    public String req5(User user){
        System.out.println("UserController save is running......"+user.getAddress().getProvince());
        return "success.jsp";
    }
    @RequestMapping("req6")
    public String req6(User user){
        System.out.println("UserController save is running......"+user);
        return "success.jsp";
    }
    @RequestMapping("req7")
    public String req7(User user){
        System.out.println("UserController save is running......"+user.getAddresses());
        return "success.jsp";
    }
    @RequestMapping("req8")
    public String req8(User user){
        System.out.println("UserController save is running......"+user.getAddressMap());
        return "success.jsp";
    }
    @RequestMapping("req9")
    public String req9(String[] nick){
        System.out.println("UserController save is running......"+nick[0]+nick[1]);
        return "success.jsp";
    }
    @RequestMapping("req10")
    public String req10(@RequestParam("nick") List<String> nicks){
        System.out.println("UserController save is running......"+nicks.toString());
        return "success.jsp";
    }
    @RequestMapping("req11")
    public String req11(Date date){
        System.out.println(date);
        return "success.jsp";
    }
    @RequestMapping("req12")
    public String req12(@DateTimeFormat(pattern = "yyyy-MM-dd") Date date){
        System.out.println(date);
        return "success.jsp";
    }
    @RequestMapping("req13")
    public String req13(User user){
        System.out.println(user);
        return "success.jsp";
    }
}
